package com.ossjk.qlh.business.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ossjk.core.base.controller.BaseController;
import com.ossjk.core.util.CommonUtil;
import com.ossjk.core.vo.RequestBean;
import com.ossjk.core.vo.ResponseBean;
import com.ossjk.qlh.business.entity.Setmeal;
import com.ossjk.qlh.business.service.ISetmealService;
import com.ossjk.qlh.business.vo.SetmealVO;
import com.ossjk.qlh.crm.service.IEnterpriseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
/**
 *  
 * 套餐
 * @author parker
 * @since 2020-08-12
 */
@Api(tags = "套餐")
@RestController
@RequestMapping("/business/setmeal")
public class SetmealController extends BaseController {
	
	@Resource
	private ISetmealService iSetmealService;
	
	@Autowired
	private IEnterpriseService iEnterpriseService;


	@ApiOperation(value = "列表")
	@RequiresPermissions("0000005512")
	@PostMapping("/list")
	public ResponseBean<Page<SetmealVO>> list(@RequestBody RequestBean requestBean) {
		QueryWrapper<SetmealVO> queryWrapper = new QueryWrapper<SetmealVO>();
		if (!CommonUtil.isBlank(requestBean.getParam().get("name"))) {
			queryWrapper.like("name", requestBean.getParam().get("name"));
		}
		if (!CommonUtil.isBlank(requestBean.getParam().get("state"))) {
			queryWrapper.like("state", requestBean.getParam().get("state"));
		}
		if (!CommonUtil.isBlank(requestBean.getParam().get("minprice"))&&!CommonUtil.isBlank(requestBean.getParam().get("maxprice"))) {
			queryWrapper.between("price",requestBean.getParam().get("minprice"),requestBean.getParam().get("maxprice"));
		}
		if (!CommonUtil.isBlank(requestBean.getParam().get("eid"))) {
			queryWrapper.like("eid", requestBean.getParam().get("eid"));
		}
		return responseSuccess(iSetmealService.findSetmealAll(requestBean.getPage(),queryWrapper));
	}

	@ApiOperation(value = "去修改")
	@RequiresPermissions("00000055120001")
	@PostMapping("/toUpdate")
	public ResponseBean<Setmeal> toUpdate(@RequestBody RequestBean requestBean) {
		Setmeal setmeal = iSetmealService.getById((Serializable) requestBean.getParam().get("id"));
		if (!CommonUtil.isBlank(setmeal)) {
			return responseSuccess(setmeal);
		} else {
			return responseFail();
		}
	}

	@ApiOperation(value = "添加")
	@RequiresPermissions("0000005512000")
	@ApiOperationSupport(ignoreParameters = { "id", "crer", "mder", "crtm", "mdtm" })
	@PostMapping("/save")
	public ResponseBean save(@RequestBody RequestBean<Setmeal> requestBean) {
		if (iSetmealService.save(requestBean.getData())) {
			return responseSuccess();
		} else {
			return responseFail();
		}
	}

	@ApiOperation(value = "修改")
	@RequiresPermissions("00000055120001")
	@ApiOperationSupport(ignoreParameters = { "crer", "mder", "crtm", "mdtm" })
	@PostMapping("/update")
	public ResponseBean update(@RequestBody RequestBean<Setmeal> requestBean) {
		if (iSetmealService.updateById(requestBean.getData())) {
			return responseSuccess();
		} else {
			return responseFail();
		}
	}

	@ApiOperation(value = "删除")
	@RequiresPermissions("0000005512002")
	@PostMapping("/remove")
	public ResponseBean delete(@RequestBody RequestBean requestBean) {
		List ids = (List) requestBean.getParam().get("ids");
		if (iSetmealService.removeByIds(ids)) {
			return responseSuccess();
		} else {
			return responseFail();
		}
	}

	@ApiOperation(value = "查找套餐名")
	@PostMapping("/selectTitle")
	public ResponseBean selectTitle() {
		List list = iSetmealService.selectTitle();
		return responseSuccess(list);
	}
	
		@ApiOperation(value = "公司信息")
	@PostMapping("/company")
	public ResponseBean<Page<com.ossjk.qlh.business.vo.EnterpriseVo>> listcompay(@RequestBody RequestBean requestBean) {

		return responseSuccess(iEnterpriseService.list());
	}
}
